import { defineStore } from "pinia";
import { ref } from "vue";
import type { User } from "@/types/user";

export const useUserStore = defineStore(
  "wiki-user",
  () => {
    // 1.定义用户信息
    const user = ref<User>();
    // 2.修改用户信息
    const setUser = (newUser: User) => (user.value = newUser);
    // 3.删除用户信息
    const delUser = () => (user.value = undefined);

    return {
      user,
      setUser,
      delUser,
    };
  },
  {
    // 开启本地持久化
    persist: true,
  },
);
